
package com.tanhua.server.controller;

import com.tanhua.server.pojo.Operation;
import com.tanhua.server.service.SoulService;
import com.tanhua.server.vo.SoulReportVo;
import com.tanhua.server.vo.SoulVo;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021/3/4 9:06
 * @version: 0.0.1
 * @modified By:
 */

@RestController
@RequestMapping("testSoul")
public class SoulController {

    @Autowired
    private SoulService soulService;
    /**
     * @description 查询报告
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping("report/{id}")
    public ResponseEntity<SoulReportVo>querySoulReport(@PathVariable("id")String reportId){
        try {
            SoulReportVo soulReportVo= this.soulService.querySoulReport(reportId);
            if(null!=soulReportVo){
                return ResponseEntity.ok(soulReportVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * @description 提交问卷
     * @author
     * @date
     * @param
     *@return
     */
    @PostMapping
    public ResponseEntity<String> sub(@RequestBody Map<String, List<Operation>> answers) {
        //通过answers得到值
        try {
            List<Operation> operationList = answers.get("answers");  //得到表里面的数据
            String sub = this.soulService.sub(operationList);
            return ResponseEntity.ok(sub);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * @description 问卷列表
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping
    public ResponseEntity<List<SoulVo>> queryQuestionnaire(){
        try {
            List<SoulVo> soulVoList = soulService.queryQuestionnaire();
            if(CollectionUtils.isNotEmpty(soulVoList)){
                return ResponseEntity.ok(soulVoList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.HTTP_VERSION_NOT_SUPPORTED).build();
    }
}

